﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Travel.Web.order
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                       
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtcode.Text.Trim().Length==0)
			{
				strErr+="订单号不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtroute_id.Text))
			{
				strErr+="线路id格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtbuyer_id.Text))
			{
				strErr+="购买者id格式错误！\\n";	
			}
			if(this.txtbuyer_name.Text.Trim().Length==0)
			{
				strErr+="购买者姓名不能为空！\\n";	
			}
			if(this.txtbuyer_phone.Text.Trim().Length==0)
			{
				strErr+="购买者手机号不能为空！\\n";	
			}
			if(this.txttraveller_name.Text.Trim().Length==0)
			{
				strErr+="游玩者姓名不能为空！\\n";	
			}
			if(this.txttravller_phone.Text.Trim().Length==0)
			{
				strErr+="游玩者手机号不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtbuy_time.Text))
			{
				strErr+="购买时间格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txttravel_time.Text))
			{
				strErr+="旅行时间格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtcost.Text))
			{
				strErr+="花费格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtstatus.Text))
			{
				strErr+="订单状态 0 未付款 1 已付格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtcreated_on.Text))
			{
				strErr+="created_on格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtchanged_on.Text))
			{
				strErr+="changed_on格式错误！\\n";	
			}
			if(this.txtchanged_by.Text.Trim().Length==0)
			{
				strErr+="changed_by不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string code=this.txtcode.Text;
			int route_id=int.Parse(this.txtroute_id.Text);
			int buyer_id=int.Parse(this.txtbuyer_id.Text);
			string buyer_name=this.txtbuyer_name.Text;
			string buyer_phone=this.txtbuyer_phone.Text;
			string traveller_name=this.txttraveller_name.Text;
			string travller_phone=this.txttravller_phone.Text;
			DateTime buy_time=DateTime.Parse(this.txtbuy_time.Text);
			DateTime travel_time=DateTime.Parse(this.txttravel_time.Text);
			decimal cost=decimal.Parse(this.txtcost.Text);
			int status=int.Parse(this.txtstatus.Text);
			DateTime created_on=DateTime.Parse(this.txtcreated_on.Text);
			DateTime changed_on=DateTime.Parse(this.txtchanged_on.Text);
			string changed_by=this.txtchanged_by.Text;

			Travel.Model.orders model=new Travel.Model.orders();
			model.code=code;
			model.route_id=route_id;
			model.buyer_id=buyer_id;
			model.buyer_name=buyer_name;
			model.buyer_phone=buyer_phone;
			model.traveller_name=traveller_name;
			model.travller_phone=travller_phone;
			model.buy_time=buy_time;
			model.travel_time=travel_time;
			model.cost=cost;
			model.status=status;
			model.created_on=created_on;
			model.changed_on=changed_on;
			model.changed_by=changed_by;

			Travel.BLL.orders bll=new Travel.BLL.orders();
			bll.Add(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","add.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
